package kr.co.sdworld.api.apns.service;

import kr.co.sdworld.api.apns.model.ApnsCert;
import kr.co.sdworld.api.apns.model.ApnsLogin;
import kr.co.sdworld.api.apns.repository.cert.ApnsCertDao;
import kr.co.sdworld.stone.SpringBeanUtil;
import kr.co.sdworld.webs.ServiceContext;

import org.springframework.stereotype.Service;

@Service
public class CertServiceImpl implements CertService
{
	@Override
	public ApnsCert saveCert( String appId, String certPath, String certPass)
	{
		ApnsCert cert = new ApnsCert();
		cert.setAppId( appId);
		cert.setCertPath( certPath);
		cert.setCertPass( certPass);

		ApnsLogin login = (ApnsLogin) ServiceContext.getSession().getAttribute( "login");
		cert.setUserId( login.getUserId());

		int result = SpringBeanUtil.repository( ApnsCertDao.class).create( cert);
		if ( result > 0)
		{
			return SpringBeanUtil.repository( ApnsCertDao.class).getApnsCert( appId);
		}
		return null;
	}
}
